<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <title> 查看暂存代码 </title>
    <link href='../../highlight/styles/shCore.css' rel='stylesheet' type='text/css'/>
    <link href='../../highlight/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/>
    <script src='../../highlight/scripts/shCore.js' type='text/javascript'></script>
    <script src='../../highlight/scripts/shBrushCpp.js' type='text/javascript'></script>
    <script src='../../highlight/scripts/shBrushCss.js' type='text/javascript'></script>
    <script src='../../highlight/scripts/shBrushJava.js' type='text/javascript'></script>
    <script src='../../highlight/scripts/shBrushDelphi.js' type='text/javascript'></script>
    <script src='../../highlight/scripts/shBrushRuby.js' type='text/javascript'></script>
    <script src='../../highlight/scripts/shBrushBash.js' type='text/javascript'></script>
    <script src='../../highlight/scripts/shBrushPython.js' type='text/javascript'></script>
    <script src='../../highlight/scripts/shBrushPhp.js' type='text/javascript'></script>
    <script src='../../highlight/scripts/shBrushPerl.js' type='text/javascript'></script>
    <script src='../../highlight/scripts/shBrushCSharp.js' type='text/javascript'></script>
    <script src='../../highlight/scripts/shBrushVb.js' type='text/javascript'></script>
</head>
<body>
<?php require("front_view_nav.php"); ?>

<div class="col-lg-offset-1 col-lg-10 col-sm-12 col-xs-12">
<div class="panel panel-default" style="margin-left: -1.3rem; margin-right: -1.3rem;">
    <div class="panel-body">
        <div id="stash_code_detail" class="col-lg-12 col-xs-12 col-sm-12">
            <div class="col-lg-12 col-sm-12 col-xs-12">
                <a class="col-sm-2" :href="problemInfoUrl(codeDetail.problem_id)">题目ID：{{codeDetail.problem_id}}</a>
                <a class="col-offset-2 col-sm-2" href="stash_code_list.php">返回</a>
                <button v-on:click="postCode(codeDetail.id)">编辑</button>
            </div>
            <!--
            <pre class="brush:c;">{{codeDetail.source}}</pre>
            -->
            <pre>{{codeDetail.source}}</pre>
        </div>
    </div>
</div>
</div>
<script>
    var app = new Vue({
        el: "#stash_code_detail",
        data:{
            codeDetail: {
                id:"",
                problem_id:"",
                problem_name:"",
                title:"",
                source:"",
            }
        },

        mounted:function () {
            SyntaxHighlighter.config.bloggerMode = false;
            SyntaxHighlighter.config.clipboardSwf = '../../highlight/scripts/clipboard.swf';
            SyntaxHighlighter.all();
            this.loadCodeInfo();
        },

        methods: {
            loadCodeInfo: function () {
                this.codeDetail.id = getUrlKey('id');
                let reqData = {};
                reqData.id = this.codeDetail.id;
                reqData.op = "fetch";
                let param = "para=" + JSON.stringify(reqData);
                new Promise(function (resolve, reject) {
                    $.ajax({
                        type: 'post',
                        url: '../model/stash_code_router.php',
                        data: param,
                        dataType: 'json',
                        success: function (retData) {
                            if (retData.status) {
                                resolve(retData.dat);
                            }
                            else {
                                reject(retData.msg);
                            }
                        },
                        error:function (dat) {
                            //alert("dddeeee");
                        },
                    });
                }).then(function (detail) {
                    app.codeDetail.id = detail.id;
                    app.codeDetail.problem_id = detail.problem_id;
                    app.codeDetail.title = detail.title;
                    app.codeDetail.source = Base64.decode(detail.source);
                }).catch(function (errMsg) {
                    alert('获取代码信息失败:'+errMsg);
                });
            },

            problemInfoUrl:function(problemId) {
                let url = "../../problem.php?id=";
                url += problemId;
                return url;
            },

            editCodeUrl:function(codeId) {
                let param = "";
                if ( ! isNull(codeId) ) {
                    param = "?id=" + codeId;
                }
                window.location.href="stash_code_post.php"+param;
            },
            // 编辑或者添加用户信息
            postCode:function(codeId) {
                let param = "";
                if ( ! isNull(codeId) ) {
                    param = "?id=" + codeId;
                }
                window.location.href="stash_code_post.php"+param;
            },
        }
    });
</script>
</body>
</html>
